using PP.Basic;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace PP.PPPoker.Game.GJ25
{
    /// <summary>
    /// GJHPEffect 对象
    /// </summary>
    public class GJHPEffect : MonoBehaviour
    {
        private const string Tag = nameof(GJHPEffect);

        // Private Variables Begin
        private AnimationTrigger AnimationTrigger => _animationTrigger ?? (_animationTrigger = transform.GetComponentEx<AnimationTrigger>());
        private AnimationTrigger _animationTrigger;
        // Private Variables End

        // Static Methods Begin
        public static GJHPEffect Create()
        {
            return null;
        }
        // Static Methods End
        
        // Public Methods Begin


        public void PlayHPLoss(int value)
        {
            gameObject.SetActive(true);

            var val = Mathf.Abs(value);
            if (GJPathHelper.HeartLossDisplay.TryGetValue(val, out string displayStr))
                _hPImage.sprite = Resources.Load<Sprite>(displayStr);


            AnimationTrigger.Play("GJHPEffectOpen", () =>
            {
                gameObject.SetActive(false);
            });
        }



        // Public Methods End
        
        // Lifecycle Methods Begin
        protected void Awake()
        {
            InitHier();
            InitPart();
        }

        private void InitPart()
        {
            // Do initialization here...
        }
        
        private void Start()
        {
            Debug.Log($"{Tag}.Start");
        }
        
        // Lifecycle Methods End


        // Hier Components Begin        
        private Image _hPImage;

        private void InitHier()
        {
            _hPImage = transform.Find("Content/_Image_HP").GetComponent<Image>();
        }


        // Hier Components End



    }
}
